home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / dev / lang / sbp3_1e.lzh / MAZE.PL < prev    next >
Text File  |  1991-10-31  |  2KB  |  48 lines

  1. /* From the book PROLOG PROGRAMMING IN DEPTH
  2.    by Michael A. Covington, Donald Nute, and Andre Vellino.
  3.    Copyright 1988 Scott, Foresman & Co.
  4.    Non-commercial distribution of this file is permitted. */
  5. /* Modified for Quintus Prolog by Andreas Siebert */
  6.  
  7. /* MAZE.PL */
  8.  
  9. solve_maze :- path([start],Solution), write(Solution).
  10.  
  11. path([OldSpot|RestOfPath],Solution) :-
  12.      connected_to(NewSpot,OldSpot),
  13.      \+ member(NewSpot,RestOfPath),
  14.      check_path([NewSpot,OldSpot|RestOfPath],Solution).
  15.  
  16. check_path([finish|Rest],[finish|Rest]).
  17. check_path(Path,Solution):- path(Path,Solution).
  18.  
  19. connected_to(A,B) :- connect(A,B).
  20. connected_to(A,B) :- connect(B,A).
  21.  
  22. member(X,[X|_]).
  23. member(X,[_|Y]) :- member(X,Y).
  24.  
  25. /*************************************************
  26.  * Connectivity table for the maze in Figure 8.2 *
  27.  *************************************************/
  28.  
  29. connect(start,2).        connect(1,7).
  30. connect(2,8).            connect(3,4).
  31. connect(3,9).            connect(4,10).
  32. connect(5,11).           connect(5,6).
  33. connect(7,13).           connect(8,9).
  34. connect(10,16).          connect(11,17).
  35. connect(12,18).          connect(13,14).
  36. connect(14,15).          connect(14,20).
  37. connect(15,21).          connect(16,22).
  38. connect(17,23).          connect(18,24).
  39. connect(19,25).          connect(20,26).
  40. connect(21,22).          connect(23,29).
  41. connect(24,30).          connect(25,31).
  42. connect(26,27).          connect(27,28).
  43. connect(28,29).          connect(28,34).
  44. connect(30,36).          connect(31,32).
  45. connect(32,33).          connect(33,34).
  46. connect(34,35).          connect(35,36).
  47. connect(32,finish).
  48.